package dw.fastfile.business.service;

import dw.fastfile.business.dto.DogClassExport;
import dw.fastfile.business.dto.DogDto;
import dw.fastfile.business.dto.DogExport;
import dw.fastfile.common.enums.EnumFieldService;
import dw.fastfile.common.exception.BusinessException;
import dw.fastfile.common.util.ExcelExportUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: wanghao
 * @create: 2023-05-04 11:22
 **/
@Slf4j
@Service
public class DogService {
    @Resource
    private EnumFieldService enumFieldService;

    public static void main(String[] args) {
        String s = "李超 0000316738";
        String substring = s.substring(s.indexOf("0"));
        System.out.println(substring);
    }

    public void save(DogDto dogDto) {

    }

    public void downIncDecSocial(HttpServletRequest req, HttpServletResponse resp) {
        String id = req.getParameter("id");
        List<DogExport> socialExceptionList = testDogExport();

        String fileName = "狗狗导出";
        try {
            ExcelExportUtil.exportExcel(socialExceptionList, DogExport.class, fileName, "增减员数据", resp);

        } catch (IOException e) {
            log.error("下载增减员数据失败", e);
            throw new BusinessException("下载增减员数据失败");
        }
    }

    public List<DogExport> testDogExport() {
        return new ArrayList<>();
    }

    public DogClassExport testTransform() {
        DogClassExport d = this.getTest();
        enumFieldService.processDict(d);
        return d;
    }

    public DogClassExport getTest() {
        DogClassExport c = new DogClassExport();
        c.setName("班级");
        c.setStatus("1");
        Set<DogExport> list = new HashSet<>();
        DogExport d = new DogExport();
        d.setAge(1);
        d.setName("小明");
        d.setType("1");

        list.add(d);

        DogExport d2 = new DogExport();
        d2.setAge(2);
        d2.setName("小红");
        d2.setType("2");

        list.add(d2);
        c.setDogExports(list);

        DogExport d3 = new DogExport();
        d3.setAge(2);
        d3.setName("小蓝");
        d3.setType("0");
        c.setMainDog(d3);

        return c;
    }


}
